/* eslint-disable prettier/prettier */
import { get, post, put, deletes } from "@/utils/request";
import api from "./resource";
//查看用户所有权限GET /v1/users/{id}/authority
export function queryUserauthority(id) {
  return get(api.users + "/" + id + "/authority", "", true).then(res => {
    if (res.success) return res.data;
  });
}
//分配系统操作权限 post /v1/roles/{id}/authority/systemauthotity
export function systemauthotityAuthority(id, data) {
  return post(
    api.roles + "/" + id + "/authority/systemAuthortity",
    data,
    true
  ).then(res => {
    if (res.success) return res;
  });
}
//分配数据类型权限post /v1/roles/{id}/authority/dataauthority
export function dataauthorityAuthority(id, data) {
  return post(
    api.roles + "/" + id + "/authority/dataAuthority",
    data,
    true
  ).then(res => {
    if (res.success) return res.data;
  });
}
//查看角色所有权限 GET /v1/roles/{id}/authority
export function queryRolesauthority(id) {
  return get(api.roles + "/" + id + "/authority", "", true).then(res => {
    if (res.success) return res.data;
  });
}
//查询所有权限GET /v1/roles/allAuthority/
export function queryAllauthority() {
  return get(api.roles + "/allAuthority", "", true).then(res => {
    if (res.success) return res.data;
  });
}

//权限二期接口
// 添加非资源目录的权限
export function resourceAuthority(data) {
  return put(`${window.ENV.API_USER}/v1/resourceAuthority`, data, true);
}
//获取角色对应的非资源目录
export function getResourceContentAuthority(id) {
  return get(`${window.ENV.API_USER}/v1/resourceAuthority/${id}`, "", true);
}
// 数据分级权限
//调用资产系统字典接口获取对应的数据
export function systemDict(type) {
  return get(`${window.ENV.API_DAM}/manager/sysDict/query?categories=${type}`, "", true);
}
//保存数据分级权限
export function saveDataLevel(data) {
  return put(`${window.ENV.API_USER}/v1/resourceAuthority/dataLevel`, data, true);
}
//获取对应角色的分级权限
export function getDataLevel(id) {
  return get(`${window.ENV.API_USER}/v1/resourceAuthority/dataLevel/${id}`, "", true);
}

//用户资源目录相关接口
//level:01 02 03
export function getUserResourceByLevel(level) {
  return get(`${window.ENV.API_DAM}/v1/dataresmenu/detail/ResAllServer`, level, true);
}
// 调用资产接口获取库区、表、字段信息
export function getDataArea(params) {
  return get(`${window.ENV.API_DAM}/v1/dataresmenu/detail/ResServer`, params, true);
}
//根据库区获取表
export function getDataAreaTable(type) {
  return post(`${window.ENV.API_DAM}/manager/dataTableAction/listData`, {
    areaType: type,
    pageNum: 1,
    pageSize: 99999
  })
}
//根据库区获取表
export function getAreaTableTB(id) {
  return get(`${window.ENV.API_DAM}/manager/dataTbColAction/listPageData`, {
    tableId: id,
    pageNum: 1,
    pageSize: 99999
  })
}
//保存用户资源目录权限
export function saveResourceAuthority(data) {
  return post(`${window.ENV.API_USER}/v1/resourceAuthority/resource`, data, true);
}
//查询角色对应的资源目录权限
export function getResourceAuthority(id, level) {
  return get(`${window.ENV.API_USER}/v1/resourceAuthority/resource/${id}`, "", true);
}

//获取字段分类权限
export function getFieldCategories() {
  return get(`${window.ENV.API_USER}/v1/authority/fieldCategories`, "", true);
}
//保存角色字段分类权限
export function putFieldCategories(id, data) {
  return put(`${window.ENV.API_USER}/v1/roles/fieldCategories/${id}`, data, true);
}
//获取角色对应的字段分类权限
export function getRoleFieldCategories(id) {
  return get(`${window.ENV.API_USER}/v1/roles/fieldCategories/${id}`, "", true);
}

//获取字段关系权限
export function getFieldConnections() {
  return get(`${window.ENV.API_USER}/v1/authority/fieldConnections`, "", true);
}
//保存字段关系权限
export function putFieldConnections(id, data) {
  return put(`${window.ENV.API_USER}/v1/roles/fieldConnections/${id}`, data, true);
}
//获取角色对应的字段关系权限
export function getRoleFieldConnections(id) {
  return get(`${window.ENV.API_USER}/v1/roles/fieldConnections/${id}`, "", true);
}

//用户资源种类的获取
export function getAllResourceType() {
  return get(`${window.ENV.API_USER}/v1/interfaceInto`);
}

//增加资源目录种类关系
export function createAuthResCategory(data) {
  return post(`${window.ENV.API_USER}/v1/authResCategory`, data, true);
}
//查询角色对应的资源种类关系
export function roleAuthResCategory(id) {
  return get(`${window.ENV.API_USER}/v1/authResCategory/${id}`, "", true);
}
